package com.buihha.audiorecorder;

import android.os.Handler;
import android.os.Message;

public class TimeThread extends Thread {
	private int time = 0;
	private Handler mHandler;
	private Mp3Recorder mRecorder;

	public static final int ING = 0;
	public static final int STOP = 1;

	public TimeThread(Handler mHandler, Mp3Recorder mRecorder) {
		this.mHandler = mHandler;
		this.mRecorder = mRecorder;
	}

	@Override
	public void run() {
		while (mRecorder.isRecording()) {
			time += 100;
			mRecorder.setTime(time);
			sendMsg(ING);
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		sendMsg(STOP);
	}

	private void sendMsg(int what) {
		Message msg = mHandler.obtainMessage();
		msg.what = what;
		msg.arg1 = mRecorder.getTime();
		msg.arg2 = mRecorder.getVolume();
		mHandler.sendMessage(msg);
	}

}
